'''
Created on Apr 12, 2011

@author: yc30v1m
'''
from plugins.TestLink import TestLink
from plugins.IniConfReader import IniConfReader
from plugins.Log import Log

class TCTestLinkMapper(object):
    '''
    classdocs
    '''
    log = Log().getLogger("TCTestLinkMapper")
    
    __testlink = None
    __reader = None

    def __init__(self):
        if self.__reader == None:
            self.__reader = IniConfReader()
        if self.__testlink == None:
            self.__testlink = TestLink()
        self.setupTestLink()
    
    def getAutomationTestCaseIds(self):
        return self.__testlink.getAllTestCaseIds()
    
    def getOptionsFromSection(self,sectionName,OptionName, testCaseId = None):
        if testCaseId != None:
            self.setTCID(testCaseId)
        return self.__testlink.getSectionAndOption(sectionName, OptionName)
        
    def setTCID(self,testCaseId):
        self.__testlink.setTCID(testCaseId)
        
    def setResult(self,result):
        self.__testlink.setTCResult(result)
    
    def setupTestLink(self):
        self.__testlink.setProjectName(self.__reader.getOptionsFromSection('testlink', 'testproject'))
        self.__testlink.setTestPlanName(self.__reader.getOptionsFromSection('testlink', 'testplan'))
        self.__testlink.setBuildName(self.__reader.getOptionsFromSection('testlink', 'testbuild'))
        self.__testlink.setAutomationScriptFileName(self.__reader.getOptionsFromSection('testlink', 'scriptfilename'))
        
    def getApiKey(self):
        return self.__reader.getOptionsFromSection('testlink', 'apikey')
        
        